<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%
  String path = request.getContextPath();
  String basePath = request.getScheme() + "://"
          + request.getServerName() + ":" + request.getServerPort()
          + path + "/";
%>
<html>
<head>
    <title></title>
  <script type="application/javascript" src="<%=basePath%>js/jquery-2.1.1.min.js"></script>
  <script type="application/javascript">
    /*定义全局变量，请求到后端的参数*/
    var id =0;
    var srcDsTable = null;
    var  tgtDsId = 0;
    $(function(){
      $.ajax({
        url:"<%=basePath%>compare/getDataSourceCombobox",
        type:"post",
        success:function(res){
          /*响应的数据添加到源数据下拉列表*/
          var data = res.data;
          if(data != null && data.length > 0){
            $("#suorce").empty();
            var sourceHtml = '<option value="-1">请选择</option>-';
            for(var i = 0;i< data.length; i++){
              sourceHtml += '<option value="'+ data[i].value+'">'+data[i].text+'</option>-';
            }
            $("#suorce").append(sourceHtml);
          }
        }
      });

      $(".src-div").hide();
      /*绑定源数据源改变事件，改变后添加数据源表到下拉列表*/
      $("#suorce").on("change",function(){
        id = $(this).val();
        alert($(this).text())
        $.ajax({
          url:"<%=basePath%>compare/getSourceTable",
          type:"post",
          data :{id:id},
          success:function(res){
            var data =res.data;
            if(data != null && data.length > 0){
              $("#table").empty();
              var sourceHtml = '<option value="-1">请选择</option>-';
              for(var i = 0;i< data.length; i++){
                sourceHtml += '<option value="'+ data[i].text+'">'+data[i].text+'</option>-';
              }
              $("#table").append(sourceHtml);
            }
          }
        });
      });
      /*赋值*/
      $("#table").on("change",function() {
         srcDsTable = $(this).val();
        alert(000)
      });
     /* 响应目标数据源，添加到下拉列表*/
        $.ajax({
          url: "<%=basePath%>compare/getTgtDataSourceCombobox",
          type: "post",
          success: function (res) {
            var data = res.data;
            if (data != null && data.length > 0) {
              $("#tgtsuorce").empty();
              var sourceHtml = '<option value="-1">请选择</option>-';
              for (var i = 0; i < data.length; i++) {
                sourceHtml += '<option value="' + data[i].value + '">' + data[i].text + '</option>-';
              }
              $("#tgtsuorce").append(sourceHtml);
            }
          }
        });
     /* 绑定改变事件赋值，并把参数传递到后台*/
      $("#tgtsuorce").on("change",function(){
          tgtDsId = $(this).val();
        /*  alert(1111)
        $.ajax({
          url:"<%=basePath%>compare/getTgtSourceTable",
          type:"post",
          data :{srcDsId:id,
                  srcDsTable:srcDsTable,
                  tgtDsId:tgtDsId
          },*/
//          success:function(res){
//            alert(111)
//            var data =res.data;
//            if(data != null && data.length > 0){
//              alert(222)
//              $("#tgttable").empty();
//              var sourceHtml = '<option value="-1">请选择</option>-';
//              for(var i = 0;i< data.length; i++){
//                sourceHtml += '<option value="'+ data[i].value+'">'+data[i].text+'</option>-';
//              }
//              $("#tgttable").append(sourceHtml);
//            }
//          }
        });
      });
    /*点击事件，传递参数到后台*/
      $("#contrast").on("click",function(){
        var source = $("#suorce").val();
        var target = $("#table").val();
        $.ajax({
          url:"<%=basePath%>compare/source",
          type:"post",
          data :{srcDsId:id,
            srcDsTable:srcDsTable,
            tgtDsId:tgtDsId
          },
          success:function(res){
            alert(res)
          }
        })
      });
  </script>
</head>
<body>
  <form id="form" method="post" action="<%=basePath%>compare/source ">
    <table border="1">
      <tr>
        <td>
          源数据源：<select id ="suorce" name="suorce">
            <%--<option value="-1">qingxuanze</option>--%>
            <%--<option value="1">plug</option>--%>
          </select>
            源数据库表名：<select id ="table" name="table"></select>
          &nbsp;&nbsp;&nbsp;&nbsp;
          目标数据源：<select id ="tgtsuorce" name="tgtsuorce"></select>
          <%--目标据库表名：<select id ="tgttable" name="tgttable"></select>--%>
        </td>
      </tr>
      <tr>
        <td align="center"><input type="button" id="contrast" value="比对"  /></td>
      </tr>
    </table>
  </form>
</body>
</html>

